#include <SFML/Graphics.hpp>
#include <math.h>
#include "Entities.h"
#include "Utils.h"
#include <iostream>
using namespace sf;

float angleTo(Vector2f Origin, Vector2f Target)
{
	return atan2((Target.y - Origin.y), (Target.x - Origin.x));// * -180/PI;
}
template <class T>

T sign(T v) { return v > 0 ? 1 : (v < 0 ? - 1 : 0); }

void viewFollow(View& v, Vector2f target, float frameTime)
{
	if (v.GetCenter() == target) { return; }
	Vector2f transform = Vector2f(v.GetCenter().x - target.x, v.GetCenter().y - target.y);
	float speed = sqrt(pow(target.x - v.GetCenter().x, 2) + pow(target.y - v.GetCenter().y, 2)) * CAMERA_SPRING;
	transform = Vector2f(-sign<float>(transform.x), -sign<float>(transform.y));
	v.Move(speed * transform.x * frameTime, speed * transform.y * frameTime);
	return;
}

Vector2f normalize(Vector2f v)
{
	float length = sqrt((v.x * v.x) + (v.y * v.y));
	if (length != 0)
		return Vector2f(v.x / length, v.y / length);
	else
		return v;
}
